package diamondServer.businesslogic.parser;

import java.util.HashMap;
import java.util.Map;

import diamondServer.businesslogic.resource.Resource;
import diamondServer.businesslogic.resource.ResourcesRepository;
import diamondServer.resources.Message;

public class ParserFake
	implements Parser
{
	private ResourcesRepository mResourcesRepository;
	
	public ParserFake(ResourcesRepository resourceRepository)
	{
		mResourcesRepository = resourceRepository;
	}

	@Override
	public Message parse(String sMessage) 
			throws ParseException
	{
		Resource resource = mResourcesRepository.getResource("ResourceFake");
		if(null==resource)
			throw new ParseException("the resource ResourceFake was not found");
		
		Message msg;
		try {
			msg = resource.getMessage().clone();
		} catch (CloneNotSupportedException e) {
			throw new ParseException("the Message is not cloneable");
		}
		
		Map<String,String> map = new HashMap<String, String>();
		map.put("body", sMessage);
		msg.fill(map);
		return msg;
	}

}
